//
//  MineUserInfoView.m
//  liangyi
//
//  Created by 张水 on 16/12/15.
//  Copyright © 2016年 yswh. All rights reserved.
//

#import "MineUserInfoView.h"

@implementation MineUserInfoView

-(instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self){
        [self setup];
    }
    return  self;
}

-(void)loadUserData:(UserModel *)model{
    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",BaseIamgeUrl,model.userHead]] placeholderImage:[UIImage imageNamed:@"user"]];
    self.userName.text = model.userName;
}

-(void)setup{
    
    WeakSelf(wk)
    
    self.backgroundColor = [UIColor ColorWithHex:@"#333942"];
    
    UIView *backView = [[UIView alloc]init];
    backView.backgroundColor = [UIColor ColorWithHex:@"#333942"];
    backView.layer.cornerRadius = 39;
    backView.layer.masksToBounds = YES;
    backView.layer.borderColor = [UIColor ColorWithHex:@"#5ac3d1"].CGColor;
    backView.layer.borderWidth = 1;
    [self addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(wk).offset(20);
        make.top.equalTo(wk).offset(30);
        make.width.height.equalTo(@80);
    }];
    
    
    self.userIcon = [UIImageView new];
    self.userIcon.layer.cornerRadius = 35;
    self.userIcon.contentMode = UIViewContentModeScaleAspectFill;
    self.userIcon.userInteractionEnabled = YES;
    self.userIcon.layer.masksToBounds = YES;
    [self addSubview:self.userIcon];
    [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(backView.mas_centerX);
        make.centerY.equalTo(backView.mas_centerY);
        make.width.height.equalTo(@74);
    }];
    
    self.userName = [[UILabel alloc]init];
    self.userName.textAlignment = NSTextAlignmentCenter;
    self.userName.textColor = [UIColor whiteColor];
    self.userName.font = [UIFont systemFontOfSize:20];
    [self addSubview:self.userName];
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userIcon.mas_right).offset(20);
        make.centerY.equalTo(self.userIcon.mas_centerY).offset(-10);
    }];
    
    
    self.loginBtn = [[UIButton alloc]init];
    [self addSubview:self.loginBtn];
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userIcon.mas_right).offset(20);
        make.centerY.equalTo(self.userIcon.mas_centerY).offset(-5);
        make.width.equalTo(@50);
        make.height.equalTo(@30);
    }];
    [self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [self.loginBtn setBackgroundColor:[UIColor clearColor]];
    [self.loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.loginBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    
    self.registBtn = [[UIButton alloc]init];
    [self addSubview:self.registBtn];
    [self.registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.loginBtn.mas_right).offset(3);
        make.centerY.equalTo(self.userIcon.mas_centerY).offset(-5);
        make.width.equalTo(@50);
        make.height.equalTo(@30);
    }];
    [self.registBtn setTitle:@"/  注册" forState:UIControlStateNormal];
    [self.registBtn setBackgroundColor:[UIColor clearColor]];
    [self.registBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.registBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    
    
    
    self.changInfoBtn = [[UIButton alloc]init];
    [self.changInfoBtn setTitle:@"修改资料" forState:UIControlStateNormal];
    [self.changInfoBtn setImage:[UIImage imageNamed:@"review"] forState:UIControlStateNormal];
    self.changInfoBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self addSubview:self.changInfoBtn];
    [self.changInfoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userName.mas_bottom).offset(10);
        make.left.equalTo(self.userName.mas_left).offset(-9);
        make.height.equalTo(@20);
        make.width.equalTo(@100);
    }];
    [self.changInfoBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, - self.changInfoBtn.imageView.bounds.size.width , 0,  self.changInfoBtn.imageView.bounds.size.width)];
    [self.changInfoBtn setImageEdgeInsets:UIEdgeInsetsMake(0, self.changInfoBtn.titleLabel.bounds.size.width,0,  - self.changInfoBtn.titleLabel.bounds.size.width)];
    
    UIView *line = [UIView new];
    line.backgroundColor = [UIColor ColorWithHex:@"#2f333a"];
    [self  addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(wk);
        make.height.equalTo(@1);
    }];
    
}



@end
